package com.qf.pojo;

import com.qf.utils.DateUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author AzureSky_X
 * @Date 2021/1/5 19:56
 * @Version 1.0
 * 用户基类
 */
public class User {
    //用户ID 主键id
    private Integer id;
    //用户名
    private String username;
    //密码
    private String password;
    //性别 0:保密 1:男 2:女
    private Integer gender;
    //邮箱
    private String email;
    //角色  0：超级管理员  1：普通用户
    private Integer role;
    //状态 0:未激活 1:已激活 2:已禁用 3:已过期
    private Integer status;
    //激活码
    private String active_code;
    //生日 时间格式
    private Date birthday;
    //生日 时间格式的字符串表现
    private String birthdaystr;

    public String getBirthdaystr() {
        //获取生日时间的字符串格式时，他的值应该是由birthday转换过来的
//        return birthdaystr;
        return DateUtil.dateToString(birthday, "yyyy-MM-dd");
}

    public void setBirthdaystr(String birthdaystr) {
//        this.birthdaystr = birthdaystr;
//        try {
//            //把birthdaystr的值通过格式化方式变成birthday
//            this.birthday=new SimpleDateFormat("yyyy-MM-dd").parse(birthdaystr);
//        } catch (ParseException e) {
//            e.printStackTrace();
//            System.out.println("日期格式转换异常");
//        }
        this.birthday = DateUtil.stringToDate(birthdaystr, "yyyy-MM-dd");

    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", gender=" + gender +
                ", email='" + email + '\'' +
                ", role=" + role +
                ", status=" + status +
                ", active_code='" + active_code + '\'' +
                ", birthday=" + birthday +
                '}';
    }

    public User(Integer id, String username, String password, Integer gender, String email, Integer role, Integer status, String active_code, Date birthday) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.gender = gender;
        this.email = email;
        this.role = role;
        this.status = status;
        this.active_code = active_code;
        this.birthday = birthday;
    }

    public User() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getGender() {
        return gender;
    }

    public void setGender(Integer gender) {
        this.gender = gender;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getRole() {
        return role;
    }

    public void setRole(Integer role) {
        this.role = role;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getActive_code() {
        return active_code;
    }

    public void setActive_code(String active_code) {
        this.active_code = active_code;
    }

    public Date getBirthday() {
//        this.birthday=new java.sql.Date(new java.util.Date().getTime());
//        SimpleDateFormat SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

//        System.out.println("这是getBirthday方法中的时间"+birthday);
        return birthday;
    }

    public void setBirthday(Date birthday) {
//        SimpleDateFormat SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        System.out.println("这是setBirthday方法中的时间"+birthday);
////        this.birthday = new java.sql.Date(new java.util.Date().getTime());
//        this.birthday= SimpleDateFormat.format(this.birthday);
        this.birthday=birthday;
    }
}
